<%@ page language="java" contentType="text/html; charset=UTF-8"	pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="ctx" value="${pageContext.request.contextPath}" />
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
        <link href="${ctx }/assets/css/bootstrap.min.css" rel="stylesheet" />
        <link rel="stylesheet" href="${ctx }/css/style.css"/>       
        <link href="${ctx }/assets/css/codemirror.css" rel="stylesheet">
        <link rel="stylesheet" href="${ctx }/assets/css/ace.min.css" />
        <link rel="stylesheet" href="${ctx }/assets/css/font-awesome.min.css" />
		<!--[if IE 7]>
		  <link rel="stylesheet" href="assets/css/font-awesome-ie7.min.css" />
		<![endif]-->
        <!--[if lte IE 8]>
		  <link rel="stylesheet" href="assets/css/ace-ie.min.css" />
		<![endif]-->
			<script src="${ctx }/assets/js/jquery.min.js"></script>

		<!--[if !IE]> -->

	


		<script type="text/javascript">
			if("ontouchend" in document) document.write("<script src='assets/js/jquery.mobile.custom.min.js'>"+"<"+"/script>");
		</script>
		<script src="${ctx }/assets/js/bootstrap.min.js"></script>
		<script src="${ctx }/assets/js/typeahead-bs2.min.js"></script>
		<!-- page specific plugin scripts -->
		<script src="${ctx }/js/jquery.page.js"></script>
        <script type="text/javascript" src="${ctx }/js/H-ui.js"></script> 
        <script type="text/javascript" src="${ctx }/js/H-ui.admin.js"></script> 
        <script src="${ctx }/assets/layer/layer.js" type="text/javascript" ></script>
        <script src="${ctx }/assets/laydate/laydate.js" type="text/javascript"></script>
<title>用户列表</title>
</head>

<body>




<div class="page-content clearfix">
    <div id="Member_Ratings">
      <div class="d_Confirm_Order_style">
    <div class="search_style">
      <div class="title_names">搜索查询</div>
      <ul class="search_content clearfix">
       <li><label class="l_f">类型名称</label><input name="" type="text"  class="text_add" placeholder="输入类型名称"  style=" width:200px" id="name"/></li>
       <li>
       	<label class="l_f" style="float: left;">信息分类</label>
       	<span class="cont_style" style="float: left; margin-left: 10px;">
		<select class="form-control" id="message_type">
		    <option value="">请选择</option>
		    <option value="1">失物招领</option>
		    <option value="2">寻物启事</option>
  		</select>
  		</span>
		</li>
       <li style="width:90px;" id="btn_search"><button type="button" class="btn_search"><i class="icon-search" ></i>查询</button></li>
      </ul>
    </div>
     <!---->
     <div class="border clearfix">
       <span class="l_f">
        <a href="javascript:void()" id="member_add" class="btn btn-warning"><i class="icon-plus"></i>添加类型</a>
        <a href="javascript:void()" class="btn btn-danger " id="member_delete"><i class="icon-trash"></i>批量删除</a>
       </span>
     </div>
     <!---->
     <div class="table_menu_list">
       <table class="table table-striped table-bordered table-hover" id="sample-table">
		<thead>
		 <tr>
			<th width="25"><label><input type="checkbox" class="ace"><span class="lbl"></span></label></th>
			<th width="80">ID</th>
			<th width="120">类型名称</th>
			<th width="120">创建时间</th>
			<th width="120">分类名称</th>
			<th width="250">操作</th>
			</tr>
		</thead>
		<tr id="firstList" style="display: none">
          <td>
          	<label><input type="checkbox" class="ace" value=""><span class="lbl"></span></label>
          	<input type="hidden" class="parent_id" value=""/>
          </td>
          <td class="type_id"></td>
          <td class="name"></td>
          <td class="create_time"></td>
          <td class="td-status"><span class="label label-success radius p_name"></span></td>
          <td class="td-manage">
	          <a title="编辑" onclick="member_edit(this)" href="javascript:;"  class="btn btn-xs btn-info" ><i class="icon-edit bigger-120"></i></a> 
	          <a title="删除" href="javascript:;"  onclick="member_del(this)" class="btn btn-xs btn-warning" ><i class="icon-trash  bigger-120"></i></a>
          </td>
		</tr>
		<tbody id="objs">
		
        
      </tbody>
      <tr><td colspan="13"><div class="tcdPageCode"></div></td></tr>
	
	</table>
   </div>
  </div>
 </div>
</div>
<!--添加用户图层-->
<div class="add_menber" id="add_menber_style" style="display:none">
    <ul class=" page-content">
    	<li>
    		<label class="label_name">信息类型：</label>
    		<span class="add_name">
    			<select class="form-control" id="_message_type">
		    <option value="1">失物招领</option>
		    <option value="2">寻物启事</option>
  		</select>
    		</span></li>
     <li><label class="label_name">类型名称：</label><span class="add_name"><input value="" name="类型名称" type="text"  class="text_add" id="_message_name"/></span></li>
    </ul>
 </div>
 
 	
<script>

	function dateformat(date){
	    var y = date.getFullYear();
	    var m = date.getMonth()+1;
	    var d = date.getDate();
	    var h = date.getHours();
	    var min=date.getMinutes(); 
	    var sec=date.getSeconds();
	    return  y+'-'+(m<10?('0'+m):m)+'-'+(d<10?('0'+d):d)+' ' +h+":"+min+":"+sec;
	    
	}
  
  	<!--提示框-->
	function alertMsg(titleName,msg){
		layer.alert(msg,{title: titleName,icon:0,}); 
	}
  	<!--搜索按钮-->
	$("#btn_search").on("click",function(){
	 	loadDatas(1,5);
	});
	<!--加载数据-->
	function loadDatas(page,size){
		var datas={"page":page,"size":size,"message_type":$("#message_type").val(),"name":$("#name").val()};
		var index=layer.load(3, {
			  shade: [0.5,'#ccc'] //0.1透明度的白色背景
		});
		
		
		$.ajax({
			  type: 'GET',
			  url: "${ctx}/auth/admin/messageType?type=typeList",
			  data: datas,
			  dataType: "json",
			  success: function(data){
				  layer.close(index);
				  if(data.returnCode==200){
					  var list=data.data.list;
					  //加载分页信息
					  console.log(data);
					  $(".tcdPageCode").createPage({
						    pageCount:data.data.last,
						    current:data.data.page,
						    backFn:function(p){
						    	console.log(p);
						    	loadDatas(p,size);
						    }
						});
					  
					  //加载列表数据
					  if(list){
						  $("#objs").html("");
						  var states=["停用","正常"];
						  var isadmins=["用户","管理员"];
						  for(var i=0;i<list.length;i++){
							  var html=$("#firstList").clone().addClass("list"+i).removeAttr("id").show();
							  $(html).find("input[type='checkbox']").val(list[i]&&list[i].id);
							  $(html).find(".type_id").html(list[i]&&list[i].id);
							  $(html).find(".name").html(list[i]&&list[i].name);
							  $(html).find(".create_time").html(list[i]&&list[i].createTime);
							  var p_id=list[i]&&list[i].parent.id;
							  if(p_id==2){
								  $(html).find(".p_name").removeClass("label-success").addClass("label-danger");
							  }
							  $(html).find(".parent_id").val(p_id);
							  $(html).find(".p_name").html(list[i]&&list[i].parent.name);
							  $("#objs").append(html).show();
						  }
						  
					  }
					  
				  }else{
					  layer.close(index);
					  alertMsg("提示框", data.returnMsg);
				  }
			  }
		});

	}
	loadDatas(1,5);
	

jQuery(function($) {
				
				$('table th input:checkbox').on('click' , function(){
					var that = this;
					$(this).closest('table').find('tr > td:first-child input:checkbox')
					.each(function(){
						this.checked = that.checked;
						$(this).closest('tr').toggleClass('selected');
					});
						
				});
			
				$('[data-rel="tooltip"]').tooltip({placement: tooltip_placement});
				function tooltip_placement(context, source) {
					var $source = $(source);
					var $parent = $source.closest('table')
					var off1 = $parent.offset();
					var w1 = $parent.width();
			
					var off2 = $source.offset();
					var w2 = $source.width();
			
					if( parseInt(off2.left) < parseInt(off1.left) + parseInt(w1 / 2) ) return 'right';
					return 'left';
				}
			})
/*用户-添加*/
 $('#member_add').on('click', function(){
    layer.open({
        type: 1,
        title: '添加类型',
		maxmin: true, 
		shadeClose: true, 
        area : ['800px' , ''],
        content:$('#add_menber_style'),
		btn:['提交','取消'],
		yes:function(index,layero){
			var datas={"message_type":$("#_message_type").val(),"message_name":$("#_message_name").val()}
			$.ajax({
				  type: 'GET',
				  url: "${ctx}/auth/admin/messageType?type=addMessageType",
				  data: datas,
				  dataType: "json",
				  success: function(data){
					  if(data.returnCode==200){
						  loadDatas(1,5);
						 $(".layui-layer-btn1").click();
						 layer.msg(data.returnMsg,{icon:1,time:1000});
					  }else{
						  alertMsg("提示框", data.returnMsg);
					  }
				  },error:function(){
					  alertMsg("提示框", "系统异常");
				  }
			});
		}
    });
});
/*用户-查看*/
function member_show(title,url,id,w,h){
	layer_show(title,url+'#?='+id,w,h);
}

/*用户-启用*/
function member_start(obj,id){
	layer.confirm('确认要启用吗？',function(index){
		$(obj).parents("tr").find(".td-manage").prepend('<a style="text-decoration:none" class="btn btn-xs btn-success" onClick="member_stop(this,id)" href="javascript:;" title="停用"><i class="icon-ok bigger-120"></i></a>');
		$(obj).parents("tr").find(".td-status").html('<span class="label label-success radius">已启用</span>');
		$(obj).remove();
		layer.msg('已启用!',{icon: 6,time:1000});
	});
}
/*用户-编辑*/
function member_edit(obj){
		var tb=$(obj).parent().parent();
		var id=$(tb).find(".type_id").html();
		$("#_message_type").val($(tb).find(".parent_id").val());
		$("#_message_name").val($(tb).find(".name").html());
	  layer.open({
        type: 1,
        title: '修改用户信息',
		maxmin: true, 
		shadeClose:false, //点击遮罩关闭层
        area : ['800px' , ''],
        content:$('#add_menber_style'),
		btn:['提交','取消'],
		yes:function(index,layero){
			var datas={"id":id,"message_type":$("#_message_type").val(),"message_name":$("#_message_name").val()}
			$.ajax({
				  type: 'GET',
				  url: "${ctx}/auth/admin/messageType?type=addMessageType",
				  data: datas,
				  dataType: "json",
				  success: function(data){
					  if(data.returnCode==200){
						  loadDatas(1,5);
						 $(".layui-layer-btn1").click();
						 layer.msg(data.returnMsg,{icon:1,time:1000});
					  }else{
						  alertMsg("提示框", data.returnMsg);
					  }
				  },error:function(){
					  alertMsg("提示框", "系统异常");
				  }
			});
		}
    });
}
	/*用户-删除*/
	function member_del(obj){
		var id=$(obj).parent().parent().find(".type_id").html();
		layer.confirm('确认要删除吗？',function(index){
			var datas={"ids":id};
			$.ajax({
				  type: 'GET',
				  url: "${ctx}/auth/admin/messageType?type=deleteMessageType",
				  data: datas,
				  dataType: "json",
				  success: function(data){
					  if(data.returnCode==200){
						  layer.msg(data.returnMsg,{icon:1,time:1000});
						  loadDatas(1,5);
					  }else{
						  alertMsg("提示框", data.returnMsg);
					  }
				  },error:function(){
					  alertMsg("提示框", "系统异常");
				  }
			});
		});
	}
	
	$("#member_delete").on("click",function(){
		var useIds=[];
		$("#objs").find("input[type='checkbox']").each(function(index,obj){
			var id=$(obj).val();
			if($(obj).is(':checked')){
				useIds.push(id);
			}
		});
		userIds=useIds.join(",");
		if(userIds==null||userIds.length<1){
			 layer.msg("请选择要删除的用户",{icon:1,time:2000});
			 return;
		}
		layer.confirm('确认要删除吗？',function(index){
			var datas={"ids":userIds};
			$.ajax({
				  type: 'GET',
				  url: "${ctx}/auth/admin/messageType?type=deleteMessageType",
				  data: datas,
				  dataType: "json",
				  success: function(data){
					  if(data.returnCode==200){
						  layer.msg(data.returnMsg,{icon:1,time:1000});
						  loadDatas(1,5);
					  }else{
						  alertMsg("提示框", data.returnMsg);
					  }
				  },error:function(){
					  alertMsg("提示框", "系统异常");
				  }
			});
		});;
	});
	
	
	

</script>
 
</body>
</html>
